package Q209

class Main {

}

class Solution {
    fun minSubArrayLen(target: Int, nums: IntArray): Int {
        var res = Int.MAX_VALUE
        var left = 0
        var sum = 0
        for (i in nums.indices) {
            sum += nums[i]
            while (sum >= target) {
                res = Math.min(res, i - left + 1)
                sum -= nums[left++]
            }
        }
        return if (res == Int.MAX_VALUE) 0 else res
    }
}
